var userAgent = navigator.userAgent.toLowerCase();
var is_ie = window.ActiveXObject && userAgent.indexOf('msie') != -1 && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

function $(id) {
    return typeof id == "string" ? document.getElementById(id) : id;
}

function ShowDIV (elm)
{
	var getelm = document.getElementById(elm);
	if(!getelm) {
		return false;
	}else{
		if(getelm.style.display=='none'){
			getelm.style.display='block';
		}
	}
}

function HideDIV (elm)
{
	var getelm = document.getElementById(elm);
	if(!getelm) {
		return false;
	}else{
		if(getelm.style.display=='block'){
			getelm.style.display='none';
		}
	}
}

function DisableID (elm)
{
	var getelm = document.getElementById(elm);
	if(!getelm) {
		return false;
	}else{
		getelm.disabled='disabled';	
	}
	
}

function EnableID (elm)
{
	var getelm = document.getElementById(elm);
	if(!getelm) {
		return false;
	}else{
		getelm.disabled='';	
	}
	
}

function select_deselectAll (formname, elm, group)
{
	var frm = document.forms[formname];
	
    for (i=0; i<frm.length; i++)
    {
        if (elm.attributes['checkall'] != null && elm.attributes['checkall'].value == group)
        {
            if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group)
              frm.elements[i].checked = elm.checked;
        }
        else if (frm.elements[i].attributes['checkme'] != null && frm.elements[i].attributes['checkme'].value == group)
        {
            if(frm.elements[i].checked == false)
            {
                frm.elements[1].checked = false;
            }
        }
    }
}

function ShowBigImage(src, delay){
	if(typeof tt != 'undefined') clearTimeout(tt);
	var e = window.event || arguments.callee.caller.arguments[0];
	var me = is_ie ? e.srcElement : e.target;
	var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);         
	var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);

	var ei = $("big_image_div");
	if(ei){
		if(ei.offsetHeight > (e.clientY-10)){
			ei.style.top  = scrollTop + e.clientY + 10 + "px";
		}else{
			ei.style.top  = scrollTop + e.clientY - ei.offsetHeight - 10 + "px";
		}
		
		if(ei.offsetWidth > (e.clientX-10)){
			ei.style.left  = scrollLeft + e.clientX + 10 + "px";
		}else{
			ei.style.left = scrollLeft + e.clientX - ei.offsetWidth - 10 + "px";
		}
	}else{
		var xx = e.clientX;
		var yy = e.clientY;
		tt = setTimeout(function() {
			var ei = document.createElement("DIV");
			ei.id = "big_image_div";
			ei.style.cssText = "padding:6px;text-align:center;border:1px solid #B2B2B2;position:absolute;background:#FFF;z-index:80000;width:160px;height:160px;";
			ei = document.body.appendChild(ei);
			ei.innerHTML = "<img src=\"" + (src ? src : me.src) + "&size=8" + "\" border=0>";
			ei.style.display = "";

			if(ei.offsetHeight > (yy - 10)){
				ei.style.top  = scrollTop + yy + 10 + "px";
			}else{
				ei.style.top  = scrollTop + yy - ei.offsetHeight - 10 + "px";
			}
			if(ei.offsetWidth > (xx - 10)){
				ei.style.left  = scrollLeft + xx + 10 + "px";
			}else{
				ei.style.left = scrollLeft + xx - ei.offsetWidth - 10 + "px";
			}
		}, (delay || delay == 0)? delay : 800);
	}

	me.onmouseout = function() {
		if(typeof tt != 'undefined') clearTimeout(tt);
		var ei = $("big_image_div");
		if(ei)	document.body.removeChild(ei);
	}
}
